import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;


public class PostcodeMenu extends JMenuBar {
    public PostcodeMenu() {
        add(createFileMenu());    //添加“文件”菜单
        add(createEditMenu());    //添加“编辑”菜单
        setVisible(true);
    }

    public static void main(String[] agrs) {
        JFrame frame = new JFrame("Postcode");
        frame.setSize(600, 500);
        frame.setJMenuBar(new PostcodeMenu());
        frame.setVisible(true);
    }

    //定义“文件”菜单
    private JMenu createFileMenu() {
        JMenu menu = new JMenu("File(F)");
        menu.setMnemonic(KeyEvent.VK_F);    //设置快速访问符
//        JMenuItem item = new JMenuItem("新建(N)", KeyEvent.VK_N);
//        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
//        menu.add(item);
        JMenuItem item = new JMenuItem("Open .csv file(O)", KeyEvent.VK_O);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
        menu.add(item);
        item = new JMenuItem("Save as json file(S)", KeyEvent.VK_S);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
        menu.add(item);
        menu.addSeparator();
        item = new JMenuItem("Exit(E)", KeyEvent.VK_E);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
        menu.add(item);
        return menu;
    }

    //定义“编辑”菜单
    private JMenu createEditMenu() {
        JMenu menu = new JMenu("Edit(E)");
        menu.setMnemonic(KeyEvent.VK_E);
        JMenuItem item = new JMenuItem("Add postcode(A)", KeyEvent.VK_A);
//        item.setEnabled(false);
        menu.add(item);
//        menu.addSeparator();
        item = new JMenuItem("Query(Q)", KeyEvent.VK_Q);
        menu.add(item);
//        item = new JMenuItem("复制(C)", KeyEvent.VK_C);
//        menu.add(item);
//        menu.addSeparator();
//        JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem("自动换行");
//        menu.add(cbMenuItem);
        return menu;
    }
}
